<?php

class Model_Orm_Auditorium extends \Orm\Model
{
    protected static $_primary_key = array('id');
    protected static $_properties = array(
            'id',
            'auditorium_name',
            'rows',
            'seats_per_row',
            'support_3d'
    );

    protected static $_table_name = 'auditoriums';

    public static function validate($factory) {
	$val = Validation::forge($factory);

	$val->add_field('Auditorium_Name', 'Auditorijas nosaukums', 'required|max_length[100]|min_length[2]');
        $val->add_field('Rows', 'Sēdvietu rindu skaits', 'required|numeric_min[5]|numeric_max[40]');
        $val->add_field('Seats', 'Sēdvietu skaits rindā', 'required|numeric_min[5]|numeric_max[50]');

	return $val;
    }
    
    public static function load_auditoriums()
    {
	return \DB::select('id', 'auditorium_name')
		    ->from('auditoriums')
		    ->execute()
		    ->as_array('id', 'auditorium_name');
    }
}
